package com.action;

import java.util.List;

import com.model.Menu;
import com.service.MenuService;
import com.service.MenuServiceImpl;


/**   
 *   
 * @author zhanghusong   
 */
public class MenuAction extends DefaultAction {

	private static final long serialVersionUID = 1L;
	MenuService service;
	List<Menu> list;
	Menu model;
	
	public MenuAction()
	{
		service = new MenuServiceImpl();
	}
	String type="";
	String msg="";
	public String list()
	{
		list = service.getMenu();
		return SUCCESS;
	}
	public String show()
	{
//		if(type.equals("add"))
//		{
//			model.setCreateUser(getAdminLoginName());
//			if(service.saveMenu(model))
//				msg = "添加成功";
//			else
//				msg = "添加失败！！请重新添加！！";
//		}
//		else if(type.equals("update"))
//		{
//			if(service.updateMenu(model))
//				msg = "更新成功！！";
//			else
//				msg = "更新失败！！请重新更新！！";
//			type = "upd";
//		}
//		else if(type.equals("del"))
//		{
//			if(service.deleteMenu(model))
//				msg = "删除成功！！";
//			else
//				msg = "删除失败！！请重新删除！！";
//		}
//		else 
		if(type.equals("upd"))
		{
			model = service.getMenuById(model);
		}
		list = service.getMenu();
		return SUCCESS;
	}
	public String save()
	{
		if(type.equals("add"))
		{
			model.setCreateUser(getAdminLoginName());
			if(service.saveMenu(model))
				msg = "菜单管理：添加成功";
			else
				msg = "菜单管理：添加失败！请重新添加！";
		}
		else if(type.equals("update"))
		{
			if(service.updateMenu(model))
				msg = "菜单管理：更新成功！";
			else
				msg = "菜单管理：更新失败！请重新更新！";
			type = "upd";
		}
		else if(type.equals("del"))
		{
			if(service.deleteMenu(model))
				msg = "菜单管理：删除成功！";
			else
				msg = "菜单管理：删除失败！请重新删除！";
		}
		return SUCCESS;
	}
	public List<Menu> getList() {
		return list;
	}
	public void setList(List<Menu> list) {
		this.list = list;
	}
	public Menu getModel() {
		return model;
	}
	public void setModel(Menu model) {
		this.model = model;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	
}
